﻿using System;

namespace DelegatesAndEventsTest
{
    enum gender
    {
        male,
        female
    }

    class Person
    {
        public event EventHandler FirstNameChanged;
        public event EventHandler LastNameChanged;
        public event EventHandler GenderChanged;
        public event EventHandler BirthDateChanged;

        string firstName;
        string lastName;
        gender personGender;
        DateTime birthday;

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                OnFirstNameChanged(value);
                firstName = value;
            }
        }

        private void OnFirstNameChanged(string value)
        {
            if (FirstNameChanged != null)
            {
                FirstNameChanged(this, new EventArgs());
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                OnLastNameChanged();
                lastName = value;
            }
        }

        private void OnLastNameChanged()
        {
            if (LastNameChanged != null)
            {
                EventArgs args = new EventArgs();
                LastNameChanged(this, args);
            }
        }

        internal gender PersonGender
        {
            get
            {
                return personGender;
            }
            set
            {
                OnGenderChanged();
                personGender = value;
            }
        }

        private void OnGenderChanged()
        {
            if (GenderChanged != null)
            {
                GenderChanged(this, new EventArgs());
            }
        }

        public DateTime Birthday
        {
            get
            {
                return birthday;
            }
            set
            {
                OnBirthDateChanged();
                birthday = value;
            }
        }

        private void OnBirthDateChanged()
        {
            if (BirthDateChanged != null)
            {
                BirthDateChanged(this, new EventArgs());
            }
        }
    }
}